package com.yanqu.road.server.logic.task.objectcondition;

import com.yanqu.road.entity.autodata.task.UserObjectTaskData;
import com.yanqu.road.entity.cricket.CricketData;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketMgr;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.logic.task.BaseObjectCondition;
import com.yanqu.road.server.protocol.GameErrorCode;

import java.util.List;
import java.util.Map;

public class CricketUpTitleObjectCondition extends BaseObjectCondition {
    @Override
    protected void changeValue(int objectId, Object object) {
        //这个成就不需要额外记录进度值
    }

    @Override
    protected int canComplete(int objectId, Integer taskId) {
        if (isAlreadyFinished(objectId, taskId)) {//不能重复完成
            return GameErrorCode.E_TASK_ALREADY_GET_REWARD;
        }
        int cricketQuality = CricketMgr.getCricketQuality(objectId);
        TaskConditionInfo taskInfo = getTaskConditionInfo(taskId);
        if (taskInfo == null) {
            return GameErrorCode.E_TASK_NO_FOUND;
        }
        int checkQuality = taskInfo.getParamList().get(0).intValue();
        if (cricketQuality != checkQuality) {
            return GameErrorCode.E_TASK_NO_FOUND;
        }

        CricketData cricketData = player.getModule(CricketModule.class).getCricketData(objectId);
        if (cricketData == null) {
            return GameErrorCode.E_CRICKET_CRICKET_NOT_FOUND;
        }

        int titleNeed = taskInfo.getParamList().get(2).intValue();
        int littleTitleNeed = taskInfo.getParamList().get(3).intValue();
        if (cricketData.getTitle() > titleNeed) {
            return 0;
        }
        if (cricketData.getTitle() >= titleNeed && cricketData.getLittleTitle() >= littleTitleNeed) {
            return 0;
        }
        return GameErrorCode.E_TASK_NOT_COMPLETE;
    }
}
